<template>
	<view class="life">
		<view class="" style="background: #fff;">
			<NavBar :title="data.index == 0?'生活':'产品服务订单'">
				<!-- <template #right>
					<view class="topRight" @tap="handeClick">
						{{data.type == 1?'买家':'卖家'}}
						<image src="/static/img/index/86.png" mode="widthFix"></image>
					</view>
				</template> -->
			</NavBar>
		</view>
		<Goods :productType="data.productType" :freeCode="data.freeCode" :countNum="data.countNum" v-if="data.index == 0" />
		<OrderList :type="data.type"  ref="orderList" v-else-if="data.index == 1"  />
		<SellerAfterSalesList  ref="sellerAfterSalesList" :type="data.type" v-else />
		<view class="bottombar">
			<view class="" @tap="data.index = 0" :style="data.index == 0?'color: #6B64D3;':''">
				<image :src="data.index == 0?'/static/img/index/171A.png':'/static/img/index/171.png'" mode="widthFix">
				</image>
				商品
			</view>
			<view class="" @tap="data.index = 1" :style="data.index == 1?'color: #6B64D3;':''">
				<image :src="data.index == 1?'/static/img/index/145A.png':'/static/img/index/145.png'" mode="widthFix">
				</image>
				订单
			</view>
			<view class="" @tap="data.index = 2" :style="data.index == 2?'color: #6B64D3;':''">
				<image :src="data.index == 2?'/static/img/index/192.png':'/static/img/index/193.png'" mode="widthFix">
				</image>
				售后
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import NavBar from '@/components/navBar.vue'
	import { nextTick, reactive,ref } from 'vue';
	import { onShow, onLoad } from '@dcloudio/uni-app'
	import { countShopping } from '@/utils/api/goods'
	import Goods from './components/goods/index.vue'
	import OrderList from './components/order/index.vue'
	import SellerAfterSalesList from './components/sellerAfterSalesList/index.vue'
	const orderList = ref()
	const sellerAfterSalesList = ref()
	const data = reactive<any>({
		index: 0,
		countNum: 0,
		type:1
	})
	onShow(() => {
		countShopping().then((res) => {
			data.countNum = res.data;
			if (data.index == -1) {
				data.index = 0;
			}
		})
	})
	onLoad((e)=>{
		data.freeCode = e.freeCode;
		data.productType = e.productType;
		getApp().globalData.getUserInfo()
		if(e.type){
			data.index = e.type
		}
		
	})
	const handeClick=()=>{
		uni.showActionSheet({
			itemList:['买家','卖家'],
			success:(e)=>{
				if(e.tapIndex){
					data.type = 2;
				}else{
					data.type = 1;
				}
				nextTick(()=>{
					console.log(data.type,'data.type')
					if(data.index == 2){
						sellerAfterSalesList.value.data.obj.pageNo = 1;
						sellerAfterSalesList.value.requstList();
					}
				})
				
			}
		})
	}
</script>

<style lang="scss">
	.life {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #F6F7F9;
	}



	.bottombar {
		padding: 10rpx 15% 20rpx 15%;
		background: #fff;
		display: flex;
		justify-content: space-between;

		view {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			image {
				width: 40rpx;
				margin-bottom: 5rpx;
			}

			font-size: 24rpx;
		}
	}

	scroll-view {
		flex: 1;
		overflow: auto;
		padding: 28rpx 0;
	}

	.topRight {
		display: flex;
		align-items: center;
		justify-content: flex-end;

		image {
			width: 36rpx;
			margin-right: 5rpx;
		}

	}
</style>